package com.hxs.learn.config.shiro;


import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.template.TemplateModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import javax.annotation.PostConstruct;

/**
 * @author huxinsheng
 */
@Component
public class ShiroTagsFreeMarkerConfig {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private final FreeMarkerConfigurer freeMarkerConfigurer;

    @Autowired
    public ShiroTagsFreeMarkerConfig(FreeMarkerConfigurer freeMarkerConfigurer) {
        this.freeMarkerConfigurer = freeMarkerConfigurer;
    }

    @PostConstruct
    public void setSharedVariable() throws TemplateModelException {
        if (logger.isDebugEnabled()) {
            logger.debug("设置freeMarker 的shiro 标签");
        }
        freeMarkerConfigurer.getConfiguration().setSharedVariable("shiro", new ShiroTags());
    }
}
